package com.jtdemo.stq.demo.controller;

import com.jtdemo.stq.demo.entity.Person;
import com.jtdemo.stq.demo.service.PersonService;
import com.jtdemo.stq.demo.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 **@Description: TODO
 **@ClassName: PersonController
 **@Author: wjt
 **@Time: 2022/6/24 19:34
 **@Version：1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/person")
public class PersonController {
    @Autowired
    private PersonService personService;

    @GetMapping("/login")
    public ResultVo login(String name, String pwd){
        return personService.isLogin(name,pwd);
    }

    @GetMapping("/pageAll")
    public ResultVo showPageAll(@RequestParam("page") int page){
        return personService.showPagePerson(page);
    }

    @GetMapping("/selectByName/{name}")
    public ResultVo selectByName(@PathVariable("name") String name,int page){
        return personService.selectPersonByName(page,name);
    }

    @PutMapping("/update")
    public ResultVo showAll(@RequestBody Person person){
      return personService.updatePerson(person);
    }

    @PostMapping("/add")
    public ResultVo addPerson(String name,String sex,int age){

        return personService.addPerson(new Person(null,name,sex,age));
    }

    @DeleteMapping("/delete/{pid}")
    public ResultVo addPerson(@PathVariable("pid") int pid){
        return personService.deletePerson(pid);
    }
}
